# /bin/bash
# File : install_ftp.sh
# Time : 2021/04/15 17:16:00
# Author : zhangxuyang
# Version : 0.1
# License : (C)Copyright 2021-2021, MIT
# Desc : None

ARRRY=($(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}'))

echo "************************************************"

read -p "请输入新建ftp用户名：" username
read -p "请输入新建ftp密码：" pwd
read -p "请输入ftp文件放置路径(如:/opt/ftp)：" path
rpm -ivh *.rpm --nodeps --force
mkdir -p $path
useradd -s /sbin/nologin -d $path $username
echo "${pwd}" | passwd --stdin $username
sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' /etc/vsftpd/vsftpd.conf
sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf

cat >> /etc/vsftpd/vsftpd.conf <<EOF
allow_writeable_chroot=YES
reverse_lookup_enable=NO
EOF

cat >> /etc/hosts.allow <<EOF
vsftpd:ALL:allow
EOF
sed -i 's/^[^#].*pam_shells.so/#&/' /etc/pam.d/vsftpd
systemctl stop firewalld;systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
getenforce
systemctl enable vsftpd
systemctl start vsftpd
chown $username:$username -R $path
echo "******************ftp安装完成,请切记以下信息*******************"
echo "ftp文件放置路径:$path"
echo "本机IP:$ARRRY"
echo "端口:21"
echo "用户名:$username"
echo "密码:$pwd"
